
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <sys/types.h>

int main(){
  pid_t id = fork();
  if(id == 0){
    //子进程
    int cnt = 5;
    while(cnt){
      printf("子进程, left %ds,pid: %d, ppid: %d\n",cnt--, getpid(), getppid());
      sleep(1);
    }
    exit(111);
  }

  sleep(2);

  //父进程
  
 // pid_t ret_id = wait(NULL);
  
  int status = 0;
  pid_t ret_id = waitpid(id, &status, 0);

  printf("父进程, pid: %d, ppid: %d, ret_id: %d, child exit code: %d, signal: %d\n", getpid(), getppid(), ret_id, (status>>8)&0xff, status&0x7f);
  
 // sleep(5);

}
